package ru.acme.lab14.net;

import ru.acme.lab14.domain.bank.Bank;
import ru.acme.lab14.service.command.CommandHandler;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class BankServer implements Runnable {
	private Bank bank;
	private int  port;
	
	public BankServer(Bank bank, int port) {
		this.bank = bank;
		this.port = port;
	}

	public void run() {
		try {
			ServerSocket serverSocket = new ServerSocket(port);
            // XXX [MY] This statement cannot complete without exception. It's bad practice.
			while (true) {
				Socket socket = serverSocket.accept();
				new Thread(new CommandHandler(bank, false, socket.getInputStream(), socket.getOutputStream())).start();
			}
		} catch (IOException e) {
			e.printStackTrace();
            // XXX [MY] It's unnecessary operator.
			return;
		}
	}

}
